"""
    学生档案管理系统
    VMC架构练习
    2024年11月23日
"""

class Student:
    """
    学生类
    name: 姓名
    age: 年龄
    sid: 学号
    score: 成绩
    """
    def __init__(self, name, age, sid, score):
        self.name = name
        self.age = age
        self.sid = sid
        self.score = score

class StudentController:
    """
    学生管理类
    """
    def __init__(self):
        self.students = []

    def add_student(self, student):
        """
        新增学生
        """
        self.students.append(student)
        print("新增成功！")
        return

    def delete_student(self, sid):
        """
        删除学生
        """
        for student in self.students:
            if sid == student.sid:
                self.students.remove(student)
                print("删除成功！")
                return

    def list_students(self):
        """
        显示所有学生信息
        """
        for student in self.students:
            print(f"Name: {student.name}, Age: {student.age}, SID: {student.sid}, Score: {student.score}")
        return
    def update_student(self, sid):
        """
        修改学生信息
        """
        for student in self.students:
            if sid == student.sid:
                print("请输入新的学生信息：")
                name = input("姓名：")
                age = input("年龄：")
                score = input("成绩：")
                student.name = name
                student.age = age
                student.score = score
                print("修改成功！")
                return

    def show_all_students(self):
        """
        显示所有学生信息
        """
        self.list_students()
        return

    def query_student(self, sid):
        """
        查询学生信息
        """
        for student in self.students:
            if sid == student.sid:
                print(f"Name: {student.name}, Age: {student.age}, SID: {student.sid}, Score: {student.score}")
                return
            else:
                print("未找到该学生信息！")
        return


class StudentView:
    """
    学生视图类
    """
    def __init__(self):
        self.controller = StudentController()

    def show_menu(self):
        """
        显示菜单
        """
        print("学生档案管理系统")
        print("1. 新增学生")
        print("2. 删除学生")
        print("3. 修改学生信息")
        print("4. 查询学生信息")
        print("5. 显示所有学生信息")
        print("6. 退出系统")

    def select_menu(self):
        """
        选择菜单
        """

        choice = input("请输入选项：")
        if choice == "1":
            self.add_student()
        elif choice == "2":
            self.delete_student()
        elif choice == "3":
            self.update_student()
        elif choice == "4":
            self.query_student()
        elif choice == "5":
            self.list_students()
        elif choice == "6":
            exit()
        else:
            print("输入错误，请重新输入！")

    def add_student(self):
        student = Student(input("姓名："), input("年龄："), input("学号："), input("成绩："))
        self.controller.add_student(student)

    def delete_student(self):
        sid = input("请输入学号：")
        self.controller.delete_student(sid)

    def update_student(self):
        sid = input("请输入学号：")
        self.controller.update_student(sid)
    def query_student(self):
        sid = input("请输入学号：")
        self.controller.query_student(sid)
    def list_students(self):
        self.controller.list_students()

if __name__ == '__main__':
    view = StudentView()
    while True:
        view.show_menu()
        view.select_menu()